import request from '@/utils/request';
import { DEFAULT_URL_SYSTEM_MANAGE } from '@/constants';

/**
 * 菜单管理-查询菜单树形列表
 */
export async function queryMenuTreeList() {
  return request(`${DEFAULT_URL_SYSTEM_MANAGE}/menuelement/treelist`);
}

/**
 * 菜单管理-查询菜单列表
 */
export async function queryMenu() {
  return request(`${DEFAULT_URL_SYSTEM_MANAGE}/menuelement`);
}

export async function queryUserPermission() {
  return request(`${DEFAULT_URL_SYSTEM_MANAGE}/menuelement/list?type=2`);
}

/**
 * 菜单管理-保存菜单
 * @param {*} option
 */
export async function saveMenu(option) {
  return request(`${DEFAULT_URL_SYSTEM_MANAGE}/menuelement`, option);
}

/**
 * 菜单管理-修改菜单
 * @param {*} option
 */
export async function updateMenu(option) {
  const { body } = option;
  return request(`${DEFAULT_URL_SYSTEM_MANAGE}/menuelement/${body.id}`, option);
}

/**
 * 菜单管理-删除菜单
 * @param {*} option
 */
export async function deleteMenu({ id }) {
  const options = { method: 'DELETE' };
  return request(`${DEFAULT_URL_SYSTEM_MANAGE}/menuelement/${id}`, options);
}
